package com.example.lib_http

import com.zyj.retrofit.adapter.FlowCallAdapterFactory
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

abstract class BaseRetrofitImpl:HttpRetrofit {

    override fun createRetrofit(client: OkHttpClient): Retrofit {
        val retrofit=Retrofit.Builder()
            .baseUrl(Concast.BASE_URL)
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(FlowCallAdapterFactory.create())
            .build()
        return retrofit
    }

    fun createOkHttpBuilder():OkHttpClient.Builder{
        val builder = OkHttpClient.Builder()
        builder
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .readTimeout(10,TimeUnit.SECONDS)
            .connectTimeout(10,TimeUnit.SECONDS)
            .writeTimeout(10,TimeUnit.SECONDS)
        return builder
    }
}